<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ artObj.title }}</span>
          <!-- 单图 -->
          <img
            v-if="artObj.cover.type === 1"
            class="thumb"
            :src="artObj.cover.images[0]"
            alt=""
          />
        </div>
        <!-- 多图 -->
        <div v-if="artObj.cover.type > 1" class="thumb-box">
          <img
            v-for="(imgSrc, index) in artObj.cover.images"
            :key="index"
            class="thumb"
            :src="artObj.cover.images[index]"
            alt=""
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>{{ artObj.aut_name }}</span>
            <span>{{ artObj.comm_count }}评论</span>
            <span>{{ formatDate(artObj.pubdate) }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon v-show="isShow" name="cross" @click.stop="onCloseClick"  />
        </div>
      </template>
    </van-cell>

  </div>
</template>

<script>
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime' // 到指定时间需要的插件
import 'dayjs/locale/zh' // 集成中文
import { mapMutations } from 'vuex'
dayjs.extend(relativeTime)
dayjs.locale('zh')
export default {
  props: {
    artObj: Object, // 文章对象
    isShow: { // 反馈x按钮的显示/隐藏
      type: Boolean,
      default: true
    }
  },
  data () {
    return {

    }
  },
  methods: {
    // 格式化时间 -- 多久之前
    formatDate (dateStr) {
      var a = dayjs()
      var b = dayjs(dateStr)
      const c = a.to(b)
      // console.log(c)
      return c
    },
    ...mapMutations(['changeActionShowMutations', 'setActionArtIdMutations']),
    onCloseClick () {
      this.changeActionShowMutations(true)
      // console.log(this.artObj.art_id)
      this.setActionArtIdMutations(this.artObj.art_id)
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;
  &:first-child {
    margin-left: 0;
  }
}

/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
